﻿using System;
namespace Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="listMethodsVastusMessage", Namespace="http://producers.ehma-10000000.xtee.riik.ee/producer/ehma-10000000", Target=typeof(ListMethodsVastusMessage))]
    public class ListMethodsVastusMessageSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IListMethodsVastusMessage clazz;
        
        public ListMethodsVastusMessageSerializer(IListMethodsVastusMessage clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("keha");
            if (clazz.Keha!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.Keha.Count);
                for (int x = 0; ((clazz.Keha != null) 
                            && (x < clazz.Keha.Count)); x = (x + 1)) {
                    if (clazz.Keha[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Keha[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="keha") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Keha = new System.Collections.Generic.List<System.String>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("keha");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>listMethodsList>item");
                            }
                            clazz.Keha.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">keha", Reader.LocalName);
            }
        }
    }
}
